﻿using Development.Network.Tcp;
using Development.Tools;

namespace Development.Network.Rpc
{
    public class RpcClient : Rpc
    {
        protected TcpClient _client;

        public bool IsConnected { get { return _client.IsConnected; } }
        public RpcClient(int bufferSize)
        {
            _client = new TcpClient(bufferSize);
            _client.EventRecvMsg += RpcRecv;
        }

      
         public void Connect(string url, bool isWait = false)
         {
             _client.Connect(url, isWait);
         }
         /// <summary>
         /// 开始连接
         /// </summary>
         /// <param name="host"></param>
         /// <param name="port"></param>
         public void Connect(string host, int port, bool isWait = false)
         {
             _client.Connect(host, port, isWait);
         }

         protected override void RpcSend(ISender sender, RpcRequst requst)
         {
             if (_client != null)
             {
                 _client.Send(requst.Pack());
             }
             else
             {
                 Log.WriteLog(ELogLevel.LOG_ERROR, "client is null");
             }
         }
    }
}
